package com.vhr.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Name MonthUtil
 * @Description:
 * @Author: CHAO
 * @Date: 2019/9/27
 */
public class MonthUtil {

    public static Date MonthDecrease(Date date){
        if(date==null){
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int month =calendar.get(Calendar.MONTH);
        calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH)-1,calendar.get(Calendar.DATE),calendar.get(Calendar.HOUR),calendar.get(Calendar.MINUTE),calendar.get(Calendar.SECOND));
        return calendar.getTime();
    }

    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(2010,9,30);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date result = MonthDecrease(calendar.getTime());
        System.out.println(format.format(result));
    }
}
